libxl: remove API for dominfolist and list that returns xc_dominfo.
authorKeir Fraser <keir.fraser@citrix.com>
Wed, 30 Dec 2009 12:45:13 +0000 (12:45 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Wed, 30 Dec 2009 12:45:13 +0000 (12:45 +0000)
fixup xl and part of libxl that use those API, to use simpler, faster
and less wasteful API (doesn't need to get the info about all domains
when looking for one specific domain).

Signed-off-by: Vincent Hanquez <vincent.hanquez@eu.citrix.com>
tools/libxl/libxl.c
tools/libxl/libxl.h
tools/libxl/libxl_dom.c
tools/libxl/xl.c

index 4af95b2057a823a284fde1f65ce22023a8e6ffad..3a042569013a07258a415b454b696ed531c6ad6a 100644 (file)
@@ -321,49 +321,6 @@ redo:
     return ptr;
 }
 
-xc_dominfo_t * libxl_domain_infolist(struct libxl_ctx *ctx, int *nb_domain)
-{
-    int index, first_domain;
-    xc_dominfo_t *info;
-    int size = 1024;
-
-    first_domain = 0;
-    index = 0;
-    info = (xc_dominfo_t *) calloc(size, sizeof(xc_dominfo_t));
-    if (!info) {
-        *nb_domain = 0;
-        return NULL;
-    }
-    *nb_domain = xc_domain_getinfo(ctx->xch, first_domain, 1024, info);
-    return info;
-}
-
-xc_dominfo_t *libxl_domain_info(struct libxl_ctx *ctx, uint32_t domid)
-{
-    xc_dominfo_t *info;
-    int rc;
-
-    info = (xc_dominfo_t *) calloc(1, sizeof(xc_dominfo_t));
-    if (!info) {
-        return NULL;
-    }
-    rc = xc_domain_getinfo(ctx->xch, domid, 1, info);
-    if (rc != 1) {
-        free(info);
-        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "Failed to get info for domain %u", 
-                        domid);
-        return NULL;
-    }
-    if (info->domid != domid) {
-        free(info);
-        XL_LOG(ctx, XL_LOG_ERROR, "Failed to get info for domain %u"
-                        ", seems to not exist anymore", domid);
-        return NULL;
-    }
-
-    return info;
-}
-
 int libxl_domain_suspend(struct libxl_ctx *ctx, libxl_domain_suspend_info *info,
                          uint32_t domid, int fd)
 {
@@ -503,28 +460,24 @@ int libxl_free_waiter(libxl_waiter *waiter)
     return 0;
 }
 
-int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_dominfo_t *info)
+int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_domaininfo_t *info)
 {
-    int nb_domain, i, rc = 0;
-    xc_dominfo_t *list = NULL;
+    int rc = 0, ret;
 
     if (event && event->type == DOMAIN_DEATH) {
-        list = libxl_domain_infolist(ctx, &nb_domain);
-        for (i = 0; i < nb_domain; i++) {
-            if (domid == list[i].domid) {
-                if (list[i].running || (!list[i].shutdown && !list[i].crashed && !list[i].dying))
+        ret = xc_domain_getinfolist(ctx->xch, domid, 1, info);
+        if (ret == 1 && info->domain == domid) {
+                if (info->flags & XEN_DOMINF_running ||
+                    (!(info->flags & XEN_DOMINF_shutdown) && !(info->flags & XEN_DOMINF_dying)))
                     goto out;
-                *info = list[i];
                 rc = 1;
                 goto out;
-            }
         }
-        memset(info, 0x00, sizeof(xc_dominfo_t));
+        memset(info, 0, sizeof(xc_dominfo_t));
         rc = 1;
         goto out;
     }
 out:
-    free(list);
     return rc;
 }
 
index 3d2843c94bef79bc7bfffbbaa8844a59e885dc22..7bfa4e594109545c0df03aa850f54c52fb2a9bf0 100644 (file)
@@ -279,7 +279,7 @@ int libxl_stop_waiting(struct libxl_ctx *ctx, libxl_waiter *waiter);
 int libxl_free_event(libxl_event *event);
 int libxl_free_waiter(libxl_waiter *waiter);
 
-int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_dominfo_t *info);
+int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_domaininfo_t *info);
 int libxl_event_get_disk_eject_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, libxl_device_disk *disk);
 
 
@@ -291,8 +291,6 @@ int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t targ
 int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
 
 struct libxl_dominfo * libxl_domain_list(struct libxl_ctx *ctx, int *nb_domain);
-xc_dominfo_t * libxl_domain_infolist(struct libxl_ctx *ctx, int *nb_domain);
-xc_dominfo_t * libxl_domain_info(struct libxl_ctx *ctx, uint32_t domid);
 
 typedef struct libxl_device_model_starting libxl_device_model_starting;
 int libxl_create_device_model(struct libxl_ctx *ctx,
index 64f0d4ed9e8a97b1fee9a8746d51079bad90550c..e87697041355fcac954e74bc4252977c911369f0 100644 (file)
@@ -245,19 +245,17 @@ static int core_suspend_callback(void *data)
     }
     XL_LOG(si->ctx, XL_LOG_DEBUG, "wait for the guest to suspend");
     while (!strcmp(state, "suspend") && watchdog > 0) {
-        int nb_domain, i;
-        xc_dominfo_t *list = NULL;
+        xc_domaininfo_t info;
+
         usleep(100000);
-        list = libxl_domain_infolist(si->ctx, &nb_domain);
-        for (i = 0; i < nb_domain; i++) {
-            if (si->domid == list[i].domid) {
-                if (list[i].shutdown != 0 && list[i].shutdown_reason == SHUTDOWN_suspend) {
-                    free(list);
-                    return 1;
-                }
-            }
+        ret = xc_domain_getinfolist(si->ctx->xch, si->domid, 1, &info);
+        if (ret == 1 && info.domain == si->domid && info.flags & XEN_DOMINF_shutdown) {
+            int shutdown_reason;
+
+            shutdown_reason = (info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask;
+            if (shutdown_reason == SHUTDOWN_suspend)
+                return 1;
         }
-        free(list);
         state = libxl_xs_read(si->ctx, XBT_NULL, path);
         watchdog--;
     }
index 6577457694ac68b39cf2c82617a011cdf29219ff..69c2dad2da1d7e71688abbbbc94642d5d1f58df8 100644 (file)
@@ -808,7 +808,7 @@ start:
     while (1) {
         int ret;
         fd_set rfds;
-        xc_dominfo_t info;
+        xc_domaininfo_t info;
         libxl_event event;
         libxl_device_disk disk;
         memset(&info, 0x00, sizeof(xc_dominfo_t));
@@ -824,10 +824,11 @@ start:
             case DOMAIN_DEATH:
                 if (libxl_event_get_domain_death_info(&ctx, domid, &event, &info)) {
                     LOG("Domain %d is dead", domid);
-                    if (info.crashed || info.dying || (info.shutdown && (info.shutdown_reason != SHUTDOWN_suspend))) {
+                    if (info.flags & XEN_DOMINF_dying || (info.flags & XEN_DOMINF_shutdown && (((info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask) != SHUTDOWN_suspend))) {
                         LOG("Domain %d needs to be clean: destroying the domain", domid);
                         libxl_domain_destroy(&ctx, domid, 0);
-                        if (info.shutdown && (info.shutdown_reason == SHUTDOWN_reboot)) {
+                        if (info.flags & XEN_DOMINF_shutdown &&
+                            (((info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask) == SHUTDOWN_reboot)) {
                             libxl_free_waiter(w1);
                             libxl_free_waiter(w2);
                             free(w1);
@@ -1320,32 +1321,26 @@ void destroy_domain(char *p)
 void list_domains(void)
 {
     struct libxl_ctx ctx;
-    xc_dominfo_t *info;
+    struct libxl_dominfo *info;
     int nb_domain, i;
 
     libxl_ctx_init(&ctx);
     libxl_ctx_set_log(&ctx, log_callback, NULL);
 
-    info = libxl_domain_infolist(&ctx, &nb_domain);
+    info = libxl_domain_list(&ctx, &nb_domain);
 
     if (info < 0) {
         fprintf(stderr, "libxl_domain_infolist failed.\n");
         exit(1);
     }
-    printf("Name                                        ID   Mem VCPUs\tState\tTime(s)\n");
+    printf("Name                                        ID   \tState\n");
     for (i = 0; i < nb_domain; i++) {
-        printf("%-40s %5d %5lu %5d     %c%c%c%c%c%c %8.1f\n",
+        printf("%-40s %5d     %c%c%c\n",
                 libxl_domid_to_name(&ctx, info[i].domid),
                 info[i].domid,
-                info[i].nr_pages * XC_PAGE_SIZE/(1024*1024),
-                info[i].nr_online_vcpus,
                 info[i].running ? 'r' : '-',
-                info[i].blocked ? 'b' : '-',
                 info[i].paused ? 'p' : '-',
-                info[i].shutdown ? 's' : '-',
-                info[i].crashed ? 'c' : '-',
-                info[i].dying ? 'd' : '-',
-                ((float)info[i].cpu_time / 1e9));
+                info[i].dying ? 'd' : '-');
     }
     free(info);
 }